package treeHoleUI;

import treeHoleDAO.AccountInformationIMPH;
import treeHoleDAO.PersonalInformationIMPH;
import treeHoleSERVICE.PostMessageIMPH;
import treeHoleSERVICE.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.List;

/**
 * @program:IntelliJ IDEA
 * @Description: 个人发帖管理页面
 * @author:Mr.zhou
 * @data: 2022/6/16 10:33
 */
public class PersonalInformationInterface extends JFrame {
    //账号
    int userAccount = new LoginInterface().getUserAccount1();
    List<User.UserHistory> UserHistory = new PostMessageIMPH().historyPostMessage(userAccount);


    private JPanel LeftSelf;
    private JButton NicknameSelf;
    private JButton ReturnSelf;
    private JScrollPane scrollPane1;
    private JPanel CenterSelf;

    public PersonalInformationInterface() {
        initComponents();
    }

    private void ReturnSelfMouseClicked(MouseEvent e) {
        // TODO add your code here
        dispose();
        new TreeHoleInterface().setVisible(true);
    }

    private void Delete1MouseClicked(MouseEvent e) {
        // TODO add your code here
        //调用删除方法

//        deleteTreeHoleContent(title);
    }

    private void LikeSelf1MouseClicked(MouseEvent e) {
        // TODO add your code here
        //调用点赞方法
//        giveLike(userName,title);
    }

    private void initComponents() {

        LeftSelf = new JPanel();
        NicknameSelf = new JButton();
        ReturnSelf = new JButton();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== LeftSelf ========
        {
            LeftSelf.setBorder ( new javax . swing. border .CompoundBorder ( new javax . swing. border .TitledBorder ( new javax . swing
                    . border .EmptyBorder ( 0, 0 ,0 , 0) ,  "JF\u006frmDesi\u0067ner Ev\u0061luatio\u006e" , javax. swing .border . TitledBorder
                    . CENTER ,javax . swing. border .TitledBorder . BOTTOM, new java. awt .Font ( "Dialo\u0067", java .
                    awt . Font. BOLD ,12 ) ,java . awt. Color .red ) ,LeftSelf. getBorder () ) )
            ; LeftSelf. addPropertyChangeListener( new java. beans .PropertyChangeListener ( ){
                @Override public void propertyChange (java . beans. PropertyChangeEvent e
        ) { if( "borde\u0072" .equals ( e. getPropertyName () ) )throw new RuntimeException( ) ;} } )
        ;
            LeftSelf.setLayout(new GridBagLayout());

            //---- NicknameSelf ----
            String userName = new AccountInformationIMPH().userName(userAccount);
            NicknameSelf.setText(userName);
            LeftSelf.add(NicknameSelf, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 5, 0), 0, 0));

            //---- ReturnSelf ----
            ReturnSelf.setText("返回");
            ReturnSelf.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    ReturnSelfMouseClicked(e);
                }
            });
            LeftSelf.add(ReturnSelf, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
        }
        contentPane.add(LeftSelf, BorderLayout.WEST);

        scrollPane1 = new JScrollPane();
        CenterSelf = new JPanel();

        int TextNumber = 1;//文章编号,第一篇文章编号为1

        for (User.UserHistory UserHistory : UserHistory){

            JPanel TextSelf1 = new JPanel();
            JScrollPane scrollPane2 = new JScrollPane();
            JTextArea TitleSelf1 = new JTextArea();
            JScrollPane scrollPane3 = new JScrollPane();
            JTextArea ArticleSelf1 = new JTextArea();
            JButton Delete1 = new JButton();
            JButton LikeSelf1 = new JButton();

            //======== scrollPane1 ========
            {

                //======== CenterSelf ========
                {
                    CenterSelf.setLayout(new GridBagLayout());

                    //======== TextSelf1 ========
                    {
                        TextSelf1.setLayout(new GridBagLayout());

                        //======== scrollPane2 ========
                        {
                            //======== TitleSelf1 ========
                            {
//                                String Title1 = UserHistory1.readTitle();
                                //调用读取List中标题的方法，返回一个Title1
//                                TitleSelf1.append(Article1);
                                TitleSelf1.setLineWrap(true);
                                TitleSelf1.append(UserHistory.title);
                                TitleSelf1.setEditable(false);
                            }
                            scrollPane2.setViewportView(TitleSelf1);
                        }
                        TextSelf1.add(scrollPane2, new GridBagConstraints(0, 0, 8, 1, 0.0, 0.0,
                                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                                new Insets(0, 0, 5, 0), 0, 0));

                        //======== scrollPane3 ========
                        {
                            //======== ArticleSelf1 ========
                            {
//                                String Article1 = UserHistory1.readArticle();
                                //调用读取List中文章的方法，返回一个Article1
//                                ArticleOther1.append(Article1);
                                ArticleSelf1.setLineWrap(true);
                                ArticleSelf1.append(UserHistory.essayContent);
                                ArticleSelf1.setEditable(false);
                            }
                            scrollPane3.setViewportView(ArticleSelf1);
                        }
                        TextSelf1.add(scrollPane3, new GridBagConstraints(0, 1, 8, 6, 0.0, 0.0,
                                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                                new Insets(0, 0, 5, 0), 0, 0));

                        //---- Delete1 ----
//                        Delete1.setText("删除");
//                        Delete1.addMouseListener(new MouseAdapter() {
//                            @Override
//                            public void mouseClicked(MouseEvent e) {
//                                int userAccount1 = new LoginInterface().getUserAccount1();
//                                String titleSelf1Text = TitleSelf1.getText();
//                                new PersonalInformationIMPH().deleteTreeHoleContent(userAccount1,titleSelf1Text);
//                                dispose();
//                                new PersonalInformationInterface();
//                                setVisible(true);
//                            }
//                        });
                        TextSelf1.add(Delete1, new GridBagConstraints(6, 7, 1, 1, 0.0, 0.0,
                                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                                new Insets(0, 0, 0, 5), 0, 0));

                        //---- LikeSelf1 ----
                        LikeSelf1.setText("点赞");
                        LikeSelf1.addMouseListener(new MouseAdapter() {
                            @Override
                            public void mouseClicked(MouseEvent e) {
                                LikeSelf1MouseClicked(e);
                            }
                        });
                        TextSelf1.add(LikeSelf1, new GridBagConstraints(7, 7, 1, 1, 0.0, 0.0,
                                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                                new Insets(0, 0, 0, 0), 0, 0));
                    }
                }

                CenterSelf.add(TextSelf1, new GridBagConstraints(0, TextNumber, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 5, 0), 0, 0));
            }
            TextNumber++;
        }
        scrollPane1.setViewportView(CenterSelf);
        contentPane.add(scrollPane1, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(getOwner());
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}
